home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / dostkerr.arc / DOSTKERR.TXT
Text File  |  1986-05-24  |  9KB  |  168 lines

  1.  TITLE:    04/21/86 PC DOS :   PC-FLASH - DOS 3.2 STACK MANAGEMENT AS
  2.             RELATED TO HARDWARE INTERRUPTS/ PAUSE KEY NOTES
  3. .
  4.  $SOURCE: ITEM 959MG  FROM EQUAL SYSTEM HONCDPD   3
  5.  SOURCE MATERIAL DATED:  APR86
  6. .
  7.  Q:
  8. Due to the confusion surrounding DOS 3.2 and its interrupt
  9. processing and a known problem with the enhanced keyboard's
  10. pause key, I will try to set the record straight.
  11. .
  12. PAUSE KEY
  13. Repeated use of the pause key while scrolling is already paused,
  14. will cause repeated interrupts, within the same interrupt
  15. handler.  This MAY lead to the exhaustion of DOS's stack pool
  16. leading to a DOS INTERNAL STACK ERROR.    This exposure was alluded
  17. to in the announcement letter under the Technical Assistance
  18. paragraph.  The supplemental information mentioned, is a software
  19. fix for the problem, which is available.  To circumvent the
  20. problem without the fix, the user need only hit the pause key
  21. once to pause scrolling, and any other key to resume scrolling
  22. since the PAUSE key is not a toggle key.
  23. .
  24. DOS 3.2
  25. DOS 3.2 has been enhanced to provide stack management for
  26. hardware interrupts, and allow the user to tune the system using
  27. the STACKS parameter of CONFIG.SYS.  This enhancement allows for
  28. the use of available applications in an environment which is
  29. interrupt intensive, i.e., high speed communications etc., at the
  30. expense of loosing memory to a stack pool.  Since most
  31. environments do not need more than 9 stacks, that number is the
  32. default and acceptable to most environments.
  33. .
  34. The following provides the details of DOS 3.2's stack management
  35. enhancement.  Only the detail necessary to explain DOS Stack
  36. Management as it relates to hardware interrupts has been
  37. provided.
  38. .
  39. DOS 3.2 Stack Management
  40. .
  41. This version of DOS has implemented a technique known as stack
  42. swapping when handling hardware interrupts.  When a hardware
  43. interrupt is generated, DOS gets control and swaps the stack that
  44. had been used for a clean DOS stack.  After swapping stacks DOS
  45. passes control to the interrupt handler associated with the
  46. hardware interrupt.  Upon return from the interrupt handler, DOS
  47. restores the old stack and adds the stack to its pool of stacks.
  48. .
  49. This implementation was necessary to allow existing applications
  50. to run in an interrupt intensive environment.  Prior to stack
  51. swapping, it was up to an application to maintain a large enough
  52. stack so that interrupt processing routines could use its stack.
  53. Hardware interrupts are unscheduled events and can occur at any
  54. time.  They may occur when executing a DOS function, an
  55. application or most importantly when another interrupt is being
  56. processed.  The last case, "when another interrupt is being
  57. processed" has an exposure.
  58. .
  59. An explanation of the exposure necessitates the understanding of
  60. how interrupts and stacks relate to one another.  We'll keep it
  61. as simple as we can.  The stack is an area of memory which can be
  62. thought of as a stack of boxes.  These boxes are used to
  63. temporarily store information.    In the case of interrupt
  64. processing, this information is the register values saved at the
  65. acknowledgement of an interrupt.  The interrupt handler saves
  66. these register values so they are preserved when the handler uses
  67. the registers for its own work.  The registers belong to the
  68. application etc.  which was running when the interrupt occurred.
  69. The interrupt handler must restore these registers when it
  70. prepares to return to the interrupted application so that
  71. application can continue processing where it was interrupted.
  72. Let's call the saving and restoring of these registers the
  73. preservation and restoration of the interrupted environment.  Do
  74. not confuse the DOS ENVIRONMENT STRINGS, with environment as
  75. discussed in this article.
  76. .
  77. Keep in mind that this environment could refer to DOS, the
  78. application or an interrupt handler, i.e., any code being executed
  79. when a hardware interrupt occurs.  So, the register values are
  80. put in the little boxes by the interrupt handler.  They are
  81. filled sequentially starting at the bottom of the stack and
  82. working up.  The pointer to the "next box" is maintained by the
  83. microprocessor.  When the interrupted environment is restored the
  84. data is taken from the boxes and placed back into the registers.
  85. The stack is allocated and defined by the application which is
  86. running.
  87. .
  88. Before the days of high speed communications (Token Ring) and
  89. multitasking the users stack was generally adequate in size to
  90. handle normal hardware interrupt processing.  Imagine, if you
  91. will, the problem encountered if an application is interrupted
  92. and the environment saved, then the interrupt handler is
  93. interrupted and the environment saved and on and on.  This could
  94. represent an interrupt intensive environment.
  95. .
  96. Note that interrupts are occurring so fast that an interrupt
  97. handler never gets a chance to restore the environment and thus
  98. free up some boxes in the stack.  If the stack is not large
  99. enough to accommodate all these saved environments then boxes are
  100. still filled even though they aren't within the allocated stack.
  101. When the stack is exceeded as discussed, an overlay condition
  102. exists where the environment was saved outside of the defined
  103. stack area.  This leads to unexplained errors such as no response
  104. from the keyboard (hang), or divide overflow or divide by zero
  105. etc, because executable instructions or data was overlayed.
  106. .
  107. Since the application defines and owns the stack, and the PC, in
  108. an increasingly number of cases, is being subject to an abundance
  109. of interrupts, DOS 3.2 was designed to utilize stack swapping.
  110. With DOS 3.2 the exposure of interrupting an interrupt handler
  111. and over utilizing the application's stack has disappeared since
  112. DOS manages the stacks used by the hardware interrupt routines.
  113. Now when an interrupt occurs the applications stack is saved and
  114. DOS passes a free DOS stack, from its pool of stacks, to the
  115. interrupt handler.  This stack is used the same way the original
  116. stack was used, to save and restore the environment.  Now when a
  117. second interrupt occurs while processing the first interrupt, DOS
  118. uses another free stack, and so forth and so on until all the
  119. environments are restored, and all the stacks swap back until,
  120. finally, the application gets its stack back and continues
  121. processing.
  122. .
  123. There aren't an infinite number of DOS stacks, so it is possible
  124. for DOS to find itself in a position that he cannot swap to a
  125. free stack because they are all being used.  This will result in
  126. an error message with DOS 3.2 which reads;
  127.        FATAL:INTERNAL STACK FAILURE, SYSTEM HALTED
  128. In the past, the user could not be notified that they had a stack
  129. problem (overlay), except by hangs and unrelated error messages.
  130. With DOS 3.2, a notice is provided prior to locking up the
  131. machine.  There is no way to recover from the error without
  132. loosing data integrity so the machine is put into a never-ending
  133. loop by DOS.  While data may be lost, the error is an indication
  134. that the number of stacks used by DOS should be increased, as
  135. your configuration is exceeding the available stack space via
  136. hardware interrupts.
  137. .
  138. A new CONFIG.SYS parameter allows the user to redefine the number
  139. of stacks to be allocated and used by DOS to prevent future
  140. errors and the subsequent lose of data.  This new parameter is
  141. the STACKS parameter and is located in the DOS users manual on
  142. page B-2.  If you are worried about experiencing this problem you
  143. could set the STACKS parameter to its maximum and have an
  144. excellent chance of never experiencing the error.  However,
  145. nothing is free, and you would have lost 32k of memory to the DOS
  146. stacks.  Since DOS is growing from release to release it is
  147. better to allow the user to set the amount of memory he can
  148. afford to utilize for stack space, rather than add another 32k to
  149. DOS.  Keep in mind that only users in an interrupt intensive
  150. environment will need to alter the default STACKS parameter.
  151. .
  152. For those of you unfamiliar with PC interrupts, the following is
  153. a partial list of some of the more popular adapters and PC
  154. functions using interrupts;
  155.        TOD CLOCK       (religiously 1 interrupt every 18.6 ms)
  156.        KEYBOARD       (pressing and releasing key)
  157.        3278/79 ADAPTER
  158.        ASYNCH ADAPTER
  159.        BSC ADAPTER
  160.        SDLC ADAPTER
  161.        NETWORK ADAPTER
  162.        TOKEN RING ADAPTER
  163.        DISKETTE DRIVE
  164.        FIXED DISK DRIVE
  165.        DACQ ADAPTER
  166.  
  167. ------------------------------
  168.